home *** CD-ROM | disk | FTP | other *** search
/ Sound Fx / Sound Fx.iso / Software / UNZIPED / MPW181-5 / _SETUP.1 / crc.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-19  |  1.4 KB  |  49 lines

  1. /*  crc.cpp
  2.  
  3.     CRC error checking */
  4.  
  5. /*
  6.  *  @(#) crc.cc 1.5, last edit: 6/15/94 16:55:30
  7.  *  @(#) Copyright (C) 1993, 1994 Tobias Bading (bading@cs.tu-berlin.de)
  8.  *  @(#) Berlin University of Technology
  9.  *
  10.  *  This program is free software; you can redistribute it and/or modify
  11.  *  it under the terms of the GNU General Public License as published by
  12.  *  the Free Software Foundation; either version 2 of the License, or
  13.  *  (at your option) any later version.
  14.  *
  15.  *  This program is distributed in the hope that it will be useful,
  16.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  *  GNU General Public License for more details.
  19.  *
  20.  *  You should have received a copy of the GNU General Public License
  21.  *  along with this program; if not, write to the Free Software
  22.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24.  
  25. #ifdef  __WIN32__
  26. #define STRICT
  27. #include <windows.h>
  28. #endif   // __WIN32__
  29.  
  30. #include "all.h"
  31. #include "crc.h"
  32.  
  33. // polynomial generator
  34. const uint16 Crc16::polynomial = 0x8005;
  35.  
  36. void Crc16::add_bits (uint32 bitstring, uint32 length)
  37. {
  38.   uint32 bitmask = 1 << (length - 1);
  39.   do
  40.      if (!(crc & 0x8000) ^ !(bitstring & bitmask))
  41.      {
  42.         crc <<= 1;
  43.         crc ^= polynomial;
  44.      }
  45.      else
  46.         crc <<= 1;
  47.   while (bitmask >>= 1);
  48. }
  49.